<template>
  <div class="container">
    <outerBox title="知识点">
      <div v-if="list.tagList">
      <el-tag :key="t"
      class="mar"
      v-for="(item , t ) in  list.tagList">{{item.tagName}}</el-tag>
      </div>
    </outerBox>
    <outerBox title="重点内容">
        <div v-if="importTagList.length">
        <el-tag :key="t" class="mar"
        v-for="(item , t ) in  importTagList">{{item.tagName}}</el-tag>
        </div>
    </outerBox>
    <div class="standardMode ov" v-if="list">
      <div class="templateContentVOListBox ov MODULE" v-if="list.editModel ==='MODULE'">
        <div class="idxBox" v-for="idxItem in list.templateContentVOList">
          <outer-box :title="idxItem.name">
          <el-row :gutter="20" class="inpItemBox">
            <el-col class="inpBarList" :span='11' v-for="item in idxItem.item">
              <h4 class="pad mar">{{item.name}}</h4>
              <div  class="marTop" >{{item.content | replaceFile(item) }}
              </div>
              <template v-if="idxItem.name==='附件'">
              <div v-if="fileUrlList.length&&item.name==='参考资料'">
               <div v-for="(files,f) in fileUrlList" :key="f">
               <FileList options="{url:'url'}"  :list="files" />
               </div>
               </div>
               </template>
             </el-col>
          </el-row>
        </outer-box>
      </div>
             </div>
      <div class="ONLINE" v-else v-html="list.content">

      </div>
    </div>

    <div class="footer-group margin30">


    </div>
  </div>
</template>

<script>

  import outerBox from '@/components/outerBox'
  import FileList from './fileList'
  export default {
    name: 'TeachingPlanInfo',
    components: {
       outerBox,
       FileList
    },
    filters:{
      replaceFile(data,item){
        var that = this
        let datar
      if(data&&item.name ==='参考资料'){
        datar = data.split('``')[0]
      }else{
        datar = data
      }
      return datar
      }
    },
    data() {
      return {
        importTagList:[],
        fileUrlList:[],
        info:{
          referFileUrl:[],//参考资料文件URl
          referVal:'',

          templateWocUrl:''
        },

      }
    },
    watch:{
      list:{
        handler:function(val){
        this.fetchData()
      },
      immediate:true
      }
    },
    created() {

    },
    mounted() {
      //
    },
    props:{
		list:{
      type:[Object,Array],
			default:()=>[]
      },
    teachingDesignResId:{
      default:'',
    },
    },
    computed: {
      teachingDesignId() {
        return this.$store.state.uploadLessonPlan.teachingPlanId
      },
      // templatePlatform() {
      //   this.info.templateContentVOList = this.$store.state.uploadLessonPlan.templatePlatform
      //   let templatePlatform = this.$store.state.uploadLessonPlan.templatePlatform
      //   return templatePlatform
      // }
    },
    methods: {
      getFileUrlList(val){
        var that = this
        console.log('val',val)
        if(val.editModel ==='MODULE'){
          val.templateContentVOList.map((items,i)=>{
           items.item.map((list,ind)=>{
               if(list.name==='参考资料'){
                var listCon = list.content.split('``')[1].split(',')
                 listCon.map((itemUrl,ind)=>{
                   that.fileUrlList.push({url:itemUrl})
                 })
               }
             })
           })
        }
      },
      fetchData(){
        let {list,info,idGetTagList} = this
        if(list.files)  info.fileIds = list.files.split(',')
        this.importTagList=idGetTagList(list.tagList)
        this.getFileUrlList(list)
        console.log("warseList",this.importTagList)
      },
      idGetTagList(taglist) {
        let newTages = []
        //
        if (!taglist) return newTages;
        if(!taglist.filter(item=>Boolean(item.tagId)===true).length) return taglist;
        if (Array.isArray(taglist)) {
          taglist.forEach(tag => {
            let b = {}
            b[tag['tagName']] = []
            console.log('d919174106b3951f tag sdsd',tag)
            for (let tagsId in tag.tags) {
              let tagsName = tag.tags[tagsId]
              b[tag['tagName']].push({
                tagsId,
                tagsName
              })
            }
            newTages.push(b)
          })
        }
        return newTages
      },
      toFilrFile(arr){
        var that = this
        var urlStr = that.findStr;
        this.info.referFileUrl.map((itUrl,i,lisData)=>{
          urlStr += itUrl.url+(i>1&&i<lisData.length-1?that.findStr:'')
        })
       arr.map((items,i)=>{
        return  items.item.map((list,ind)=>{
            if(list.name==='参考资料'){
             return list.content = that.info.referVal+ urlStr
            }
          })
        })
        return arr
      }

    }

  }
</script>
<style lang="scss">

</style>
<style lang="scss" scoped>
  .container {

  }
</style>
